<template>
    <div>
        <!--面包屑导航区域-->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home_admin' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司审核</el-breadcrumb-item>
        </el-breadcrumb>
        <!--卡片视图区域-->
        <el-card>
            <!--搜索区域-->
            <el-row :gutter="20">
                <el-col :span="9">
                    <el-input placeholder="Please input" v-model="queryInfo.query" clearable @clear="getcom_adminList">
                        <template #append>
                            <el-button type="primary" @click="getcom_adminList">
                                <el-icon style="vertical-align: middle;">
                                    <search />
                                </el-icon>
                                <span style="vertical-align: middle;"> Search </span>
                            </el-button>
                        </template>
                    </el-input>
                </el-col>
                <el-col :span="4"></el-col>
            </el-row>
            <!--岗位列表区域-->
            <el-table :data="comlist" :border="true" :stripe="true">
                <el-table-column prop="compID" label="公司编号"></el-table-column>
                <el-table-column prop="name" label="公司名称"></el-table-column>
                <el-table-column prop="com_type" label="公司类别"></el-table-column>
                <el-table-column prop="status" label="审核状态"></el-table-column>
                <el-table-column label="公司详情">
                    <template v-slot="scope">
                        <el-button type="success" @click="showDialog(scope.row.compID)">查看详情</el-button>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template v-slot="scope">
                        <el-switch v-model="scope.row.status" @change="check(scope.row)" />
                    </template>
                </el-table-column>
            </el-table>
            <!--分页区域-->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="queryInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="queryInfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
        <!--查看详情对话框-->
        <el-dialog title="岗位详情" v-model="Visible" width="50%" @close="DialogClosed">
            <!--内容主体区域-->
            <el-descriptions class="margin-top" title="详情信息" :column="3" :size="size" border>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            公司编号
                        </div>
                    </template>
                    {{this.detail.compID}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            公司名称
                        </div>
                    </template>
                    {{this.detail.name}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            公司类别
                        </div>
                    </template>
                    {{this.detail.com_type}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            地址
                        </div>
                    </template>
                    {{this.detail.ADDR}}
                </el-descriptions-item>
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            成立日期
                        </div>
                    </template>
                    {{this.detail.FoundDate}}
                </el-descriptions-item>
                
                <el-descriptions-item>
                    <template #label>
                        <div class="cell-item">
                            公司简介
                        </div>
                    </template>
                    {{this.detail.Intro}}
                </el-descriptions-item>
            </el-descriptions>
            <!--底部区域-->
            <span slot="footer" class="dialog-footer">
                <el-button @click="Visible = false" class="btns">关 闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            pages: [

            ],
            comlist: [

            ],
            //查看公司详情
            detail: {

            },
            total: 0,
            //控制查看详情对话框的显示与隐藏
            Visible: false
        }
    },
    created() {
        this.getcom_adminList();
    },
    methods: {
        async getcom_adminList() {
            const { data: res } = await this.$http.post('getAllCompanyList', this.queryInfo);
            if (res.data.size === 0) {
                return this.$message.error('获取公司信息失败！')
            }
            this.comlist = [];
            console.log(res);
            this.total = res.pageTotal;
            for(var i = 0; i < this.total; i++) {
                this.comlist.push(
                    {
                        compID: res.data.companyList[i].compID,
                        name: res.data.companyList[i].name,
                        com_type: res.data.companyList[i].com_type,
                        status: res.data.companyList[i].status == 1 ? true: false
                    }
                );
            }

        },
        //监听pagesize 改变的事件
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getcom_adminList();
        },
        //监听页码值改变的事件
        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getcom_adminList();
        },
        //修改审核状态
        async check(cominfo) {
            const id = cominfo.compID;
            const status = cominfo.status;

            const json0 = {
                compID: id,
                status: 1
            }
            const json1 = {
                compID: id,
                status: 0
            }

            const json = status ? json0 : json1;

            const { data: res } = await this.$http.post('accessCompany', json);
            if (res.error_code === "false") {
                return this.$message.error('修改审核状态失败！');
            }
            return this.$message.success('修改审核状态成功！');

        },
        //监听查看详情对话框的关闭事件
        DialogClosed() {
            this.Visible = false;
        },
        //展示查看详情对话框
        async showDialog(id) {
            const json = {
                compID: id
            };
            const { data: res } = await this.$http.post('getCompanyInfoByID', json);
            console.log(res);
            if (res.error_code !== 0) {
                return this.$message.error('查看详情失败！')
            }
            this.detail = res.data;
            this.detail.status = res.data.flag;
            this.Visible = true;
        }
    }
}
</script>

<style lang="less" scoped>
.btns {
    margin-top: 15px;
}
</style>